using System.Collections.Generic;
using Sixeyed.CodeGeneration.Metadata.Bases;
using Sixeyed.CodeGeneration.Metadata.Database.Items;
using Sixeyed.CodeGeneration.Metadata.Interfaces;
using Sixeyed.CodeGeneration.Metadata.Database.Providers.Bases;

namespace Sixeyed.CodeGeneration.Metadata.Database.Providers
{
    /// <summary>
    /// Provider for returning <see cref="StoredProcedure"/> metadata items
    /// </summary>
    /// <remarks>
    /// Provider shows all available stored procedures for selection.
    /// Stored procedure name is used as the key for the metadata item.
    /// </remarks>
    public class StoredProcedureProvider : DatabaseProviderBase
    {
        #region Constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public StoredProcedureProvider() { }

        #endregion

        #region Overridden members

        /// <summary>
        /// Gets the provider name
        /// </summary>
        public override string Name
        {
            get { return "Stored Procedure Provider"; }
        }

        /// <summary>
        /// Gets the provider description
        /// </summary>
        public override string Description
        {
            get { return  "Retrieves metadata representing a Stored Procedure"; }
        }

        /// <summary>
        /// Gets the name of the returned metadata item type
        /// </summary>
        public override string ItemTypeName
        {
            get { return  "Stored Procedure"; }
        }

        /// <summary>
        /// Returns a list of available stored procedures
        /// </summary>
        /// <returns>List of stored procedure names</returns>
        public override List<string> GetItemNames()
        {
            return this._source.GetItemNames(DatabaseItemType.StoredProcedure);
        }

        /// <summary>
        /// Returns a populated metadata item
        /// </summary>
        /// <param name="itemKey">Stored procedure name</param>
        /// <returns>Populated <see cref="StoredProcedure"/></returns>
        public override IMetadataItem GetItem(string itemKey)
        {
            StoredProcedure procedure = this.CreateItem<StoredProcedure>(itemKey);
            procedure.Key = itemKey;
            procedure.TypedItem = this._source.GetItemCommand(DatabaseItemType.StoredProcedure, itemKey);
            return procedure;
        }

        #endregion
    }
}
